MicroPython and the Internet of Things by Grinberg Miguel

MicroPython and the Internet of Things by Grinberg Miguel

Author:Grinberg, Miguel
Language: eng
Format: epub
Publisher: Softcover
Published: 2019-04-25T00:00:00+00:00


This function considers any response that comes back with a status code of 400 or higher as an error. Note how I’m adding print() statements that provide information about what’s going on in the application. These are obviously not going to be seen anywhere when you are running the device standalone, but the point of having them there is that you can also run these functions from the REPL, and in that case you will want to know what happens.

Here is an almost complete version of main.py with this application:

import network import time import urequests import config def connect_wifi(): ap_if = network.WLAN(network.AP_IF) ap_if.active(False) sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('Connecting to WiFi...') sta_if.active(True) sta_if.connect(config.WIFI_SSID, config.WIFI_PASSWORD) while not sta_if.isconnected(): time.sleep(1) print('Network config:', sta_if.ifconfig()) def call_webhook(): print('Invoking webhook') response = urequests.post(config.WEBHOOK_URL, json={'value1': config.BUTTON_ID}) if response.status_code < 400: print('Webhook invoked') else: print('Webhook failed')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.